package au.com.introprogexercise.core.excercises;

import java.util.ArrayList;

/**
 * Created by olga on 31/05/14.
 */
public class PrimeFactorExercise
{
    public static Integer[] generate(int number)
    {
        if( number == 1|| number== 2 || number == 3 || number == 5)
            return new Integer[0];

        ArrayList<Integer> primeFactorList = new ArrayList<Integer>();
        generate( number, primeFactorList );
        return primeFactorList.toArray(new Integer[primeFactorList.size()]);
    }

    public static ArrayList<Integer> generate(int number, ArrayList<Integer> primeFactorList)
    {
        if( FizzBuzzExercise.isDivisible(number, 2) )
        {
            number = number/2;
            primeFactorList.add(2);
            generate(number, primeFactorList);
        }
        else if ( FizzBuzzExercise.isDivisible(number, 3))
        {
            number = number/3;
            primeFactorList.add(3);
            generate(number, primeFactorList);
        }
        else if ( FizzBuzzExercise.isDivisible(number, 5))
        {
            number = number/5;
            primeFactorList.add(5);
            generate(number, primeFactorList);
        }
        else if( number != 1)
        {
            primeFactorList.add(number);
        }
        return primeFactorList;
    }
}
